//
//  ViewController.m
//  SDemo
//
//  Created by gg on 2018/7/2.
//  Copyright © 2018年 gg. All rights reserved.
//

#import "ViewController.h"
#import "SHMultithreadViewController.h"
#import "SHGCDViewController.h"
#import "SHOperationViewController.h"
#import "SHRuntimeViewController.h"
#import "SHRuntimeModelViewController.h"
#import "SHLayoutViewController.h"
#import "SHJSChangeViewController.h"
#import "SHJavaScriptCoreViewController.h"
#import "SHWebViewController.h"
#import "SHBlockOneViewController.h"
#import "SHArrayViewController.h"
#import "SHKVOViewController.h"
#import "SHKVCViewController.h"
#import "SHBasicAnimaViewController.h"
#import "SHTimerViewController.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) UITableView *tabelView;

@property (copy, nonatomic) NSArray * titleArr;

@end

@implementation ViewController


//init -- lazy method --
-(UITableView *)tabelView {
    if (!_tabelView) {
        _tabelView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tabelView.delegate = self;
        _tabelView.dataSource = self;
        _tabelView.backgroundColor = [UIColor yellowColor];
        _tabelView.tableFooterView = [UIView new];
       
    }
    
    return _tabelView;
}

- (NSArray *)titleArr {
    if (!_titleArr) {
        _titleArr = @[@[@"多线程详解",@"GCD",@"NSOperatetion",@"Runtime运行时",@"runtime模型转字典",@"布局优先级"],@[@"js与原生欧辰相互调用",@"认识JavaScriptCore 框架",@"UIWebView拦截URL"],@[@"block 相关"],@[@"数组copy"],@[@"KVO 底层实现",@"KVC 详解"],@[@"view动画"],@[@"定时器"]];
    }
    return _titleArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"主菜单";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tabelView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64);
    [self.view addSubview:self.tabelView];
    
    NSString *name1 = @"qwweeewewweqwqwewrrr";
    NSString *name2 = @"rrr";
    
    NSRange range;
    range = [name1 rangeOfString:name2];
    
    
    if (range.location != NSNotFound) {
        NSLog(@"found at location = %lu, length = %lu",(unsigned long)range.location,(unsigned long)range.length);
    }else{
        NSLog(@"Not Found");
    }
    
    
}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return  self.titleArr.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  [self.titleArr[section] count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
    }
    
    cell.textLabel.text = self.titleArr[indexPath.section][indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *vc;
    switch (indexPath.section) {
        case 0:
            switch (indexPath.row) {
                case 0:
                    vc = [[SHMultithreadViewController alloc] init];
                    break;
                case 1:
                    vc = [[SHGCDViewController alloc] init];
                    break;
                    
                case 2:
                    vc = [[SHOperationViewController alloc] init];
                    break;
                    
                case 3:
                    vc = [[SHRuntimeViewController alloc] init];
                    break;
                    
                case 4:
                    vc = [[SHRuntimeModelViewController alloc] init];
                    break;
                case 5:
                    vc = [[SHLayoutViewController alloc] init];
                    break;
                    
                default:
                    break;
            }
            break;
            
          
        case 1 :
            switch (indexPath.row) {
                case 0:
                    vc = [[SHJSChangeViewController alloc] init];
                    break;
                case 1:
                    vc = [[SHJavaScriptCoreViewController alloc] init];
                    break;
                    
                case 2:
                    vc = [[SHWebViewController alloc] init];
                    break;
                    
                case 3:
                   
                    break;
                    
                case 4:
                   
                    break;
                case 5:
    
                    break;
                default:
                    break;
            }
            break;
            
        case 2 :
            switch (indexPath.row) {
                case 0:
                    vc = [[SHBlockOneViewController alloc] init];
                    break;
                case 1:
                    vc = [[SHJavaScriptCoreViewController alloc] init];
                    break;
                    
                case 2:
                    vc = [[SHWebViewController alloc] init];
                    break;
                    
                case 3:
                    
                    break;
                    
                case 4:
                    
                    break;
                case 5:
                    
                    break;
                default:
                    break;
            }
            break;
            
            
        case 3 :
            switch (indexPath.row) {
                case 0:
                    vc = [[SHArrayViewController alloc] init];
                    break;
                case 1:
                    vc = [[SHJavaScriptCoreViewController alloc] init];
                    break;
                    
                case 2:
                    vc = [[SHWebViewController alloc] init];
                    break;
                    
                
            }
            break;
            
            case 4:
            switch (indexPath.row) {
                case 0:
                    vc = [SHKVOViewController new];
                    break;
                case 1:
                    vc = [SHKVCViewController new];
                    break;
                    
                default:
                    break;
            }
            break;
            
        case 5:
            switch (indexPath.row) {
                case 0:
                    vc = [SHBasicAnimaViewController new];
                    break;
                case 1:
                    vc = [SHKVCViewController new];
                    break;
                    
                default:
                    break;
            }
            break;
            
        case 6:
            switch (indexPath.row) {
                case 0:
                    vc = [SHTimerViewController new];
                    break;
                case 1:
                    vc = [SHKVCViewController new];
                    break;
                    
                default:
                    break;
            }
            break;
        
        default:
            break;
    }
    
    
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
